OPEN LIBRARY BOOK SEARCH  v1.1  -  a VisualNEO Win + HTML5 (WebView2) demo
by Anthony C - The Esoteric Webmaster (esoteric-apps.com)

Search millions of books on Open Library (openlibrary.org, a free service of the Internet Archive) and see the
results as a grid of covers. Click a cover, or "View on Open Library", to open that book's page in your web browser.
Light or dark skin, English or Spanish: both switches are in the top bar, and the app remembers them.

  v1.1: light and dark skins; English and Spanish; VisualNEO keeps both choices in settings.ini.


WHAT YOU NEED
  - VisualNEO Win with the Modern Web Browser (WebView2) object. No plug-ins.
  - An internet connection (the page talks to Open Library directly; no account or key is needed).


FILES
  OpenLibrary_Demo.pub   the VisualNEO Win project: one page, one browser object, about 40 lines of NeoScript
  Web\index.html         the whole interface: HTML, CSS and JavaScript in one file
  tools\build_pub.py     (optional) the script that wrote the .pub
  tools\test.js          (optional) an automated test of the page (Node + Playwright)

  Open OpenLibrary_Demo.pub in VisualNEO Win and press Run. Keep the Web folder next to the .pub.
  You can also open Web\index.html straight in Chrome or Edge to try the page on its own; books then open in a
  new tab, the Exit button is hidden, and the skin and language are kept by the browser instead.


HOW IT WORKS
  The idea: let the web page do everything a web page is good at, and let VisualNEO do only what a web page
  cannot do by itself.

  1. The page (Web\index.html)
     - draws the search bar, the grid of cards and the "More results" button;
     - searches Open Library itself with fetch():
         https://openlibrary.org/search.json?q=Emmet+Fox&fields=key,title,...&limit=24&page=1
       Open Library allows this from a local page, so VisualNEO is not involved in the search at all;
     - shows the covers straight from covers.openlibrary.org with ordinary <img> tags.

  2. The page -> VisualNEO
     A web page inside the app cannot start your web browser or close the program, so it asks VisualNEO:
         window.chrome.webview.postMessage('web:https://openlibrary.org/works/OL45804W')
         window.chrome.webview.postMessage('exit')
     It also asks VisualNEO to keep its settings (see 5):
         window.chrome.webview.postMessage('get:')            "send me the saved settings"
         window.chrome.webview.postMessage('set:light|es')    "save these settings"
     The browser object's properties make this arrive in NeoScript:
         Allow Web Messages ........ on (it is OFF by default - without it messages are silently dropped)
         Allowed Message Origins ... file://
         Message Variable .......... [MainMsg]
         Message Received Action ... GoSub "MainMessage"

  3. VisualNEO (the subroutine MainMessage)
         SubStr "[MainMsg]" "1" "4" "[Op]"              the command: the first 4 letters ("web:" or "exit")
         StrDel "[MainMsg]" "1" "4" "[Arg]"             the rest: the address
         If "[Op]" "=" "web:"
           . only Open Library pages are opened, so a page can never start programs or open files
           SubStr "[Arg]" "1" "24" "[S1]"
           If "[S1]" "=" "https://openlibrary.org/"
             Run "explorer.exe" "[#34][Arg][#34]" "" "Normal" "[RunResult]"
             BrowserV2PostMessage "MainBrowser" "opnd:[Arg]"
           EndIf
         EndIf
         If "[Op]" "=" "exit"
           Exit "" ""
         EndIf

  4. VisualNEO -> the page
     BrowserV2PostMessage sends a string back. The page listens for it:
         window.chrome.webview.addEventListener('message', ev => { ... ev.data ... })
     Here VisualNEO answers "opnd:<address>" and the page shows "Opened in your web browser".

  5. Settings that survive a restart (the skin and the language)
     A local page cannot rely on its own storage, so VisualNEO keeps the settings in an .ini file:
         . Startup: AppData\Local\Open Library Book Search\settings.ini (always writable)
         SetVar "[CfgDir]" "[TempDir]\..\Open Library Book Search\"
         IniRead "[CfgDir]settings.ini" "App" "Prefs" "dark|en" "[Prefs]"
         . In MainMessage:
         If "[Op]" "=" "get:"
           BrowserV2PostMessage "MainBrowser" "pref:[Prefs]"
         EndIf
         If "[Op]" "=" "set:"
           SetVar "[Prefs]" "[Arg]"
           IniWrite "[CfgDir]settings.ini" "App" "Prefs" "[Prefs]"
         EndIf
     The page decides what the value means ("light|es"); NeoScript only stores it and hands it back.
     So adding a third setting later is a change to the page alone.

  6. The skins and the languages are pure HTML/CSS/JS
     - Skins: every colour is a CSS variable, with one set for [data-theme="dark"] and one for
       [data-theme="light"]. Switching skin changes one attribute on the <html> tag.
     - Languages: every word of the interface is in one table (T.en and T.es in index.html). Elements carry
       data-t="key" (text), data-t-tip (hover hint) or data-t-ph (placeholder), and one function fills them in.
       To add a language, copy the T.en block, translate it, and add a button.

  That is the whole pattern. A bigger app adds more commands to the same subroutine (read a file, save a file,
  open a Windows dialog, remember a setting in an .ini file), and the page keeps doing all the drawing.


TIPS
  - Keep one subroutine per browser object, and give every command the same length (here 4 characters) so
    one SubStr/StrDel pair splits any message.
  - Check what a page asks for before doing it (here: only Open Library addresses), as you would with any
    input from outside NeoScript.
  - window.chrome.webview exists only inside the app. Test for it, and the same page also works in an ordinary
    browser while you design it.
  - The browser object's User Data Folder is set to [TempDir]\..\Open Library Book Search\WebView, so the
    WebView2 cache is not written into the program folder.

Book data and covers: Open Library (openlibrary.org). Please keep requests reasonable: the page asks only for
the fields it shows, 24 books at a time.
